URL = "http://downloads.sourceforge.net/project/freetype/freetype2/%(VERSION)s/freetype-%(VERSION)s.tar.bz2"
DEFAULT_VERSION = "2.4.4"
VERSIONS = ["2.4.4"]

#freetypelib = "freetype244"

from source.builders import ConfigureMakeBuilder, VisualStudioBuilder
import shutil, os

class FreeTypeWindowsBuilder( VisualStudioBuilder ):

  def installpath(self):
    return os.path.join(self.extractedpath, "binaries")

  def make(self):
    os.chdir( self.extractedpath )    
    #always build both debug and release
    self.build()

  def build(self ):
    if self.machine.bits == 64:
      self.convertProjTo64("builds\\win32\\vc2005\\freetype.vcproj")
      self.convertSolutionTo64("builds\\win32\\vc2005\\freetype.sln")
    
      self.execute( "devenv builds\\win32\\vc2005\\freetype.vcproj /Build \"LIB Debug\" " )
      self.execute( "devenv builds\\win32\\vc2005\\freetype.vcproj /Build \"LIB Release\" " )
  
  def install(self ):
    pass
  
  def copy(self):
    os.chdir( self.extractedpath )
    print "deleting targetpath before copy: ", self.targetpath()
    shutil.rmtree( self.targetpath() )    
    self.copydir( "include", self.targetpath()+"/include")
    self.copydir( "objs/win32/vc2005/", self.targetpath()+"/lib")
    self.copypattern( self.installpath(), "buildext", self.targetpath() )

class FreeTypeWindowsVS2008Builder( FreeTypeWindowsBuilder ):
    
  def build(self ):
    if self.machine.bits == 64:
      self.convertProjTo64("builds\\win32\\vc2008\\freetype.vcproj")
      self.convertSolutionTo64("builds\\win32\\vc2008\\freetype.sln")
    self.execute( "devenv builds\\win32\\vc2008\\freetype.vcproj /Build \"LIB Debug\" " )
    self.execute( "devenv builds\\win32\\vc2008\\freetype.vcproj /Build \"LIB Release\" " )

  def copy(self):
    os.chdir( self.extractedpath )      
    #print "deleting targetpath before copy: ", self.targetpath
    #shutil.rmtree( self.targetpath )
    self.copydir( "include", self.targetpath()+"/include")
    self.copydir( "objs/win32/vc2008/", self.targetpath()+"/lib")
    self.copypattern( self.installpath(), "buildext", self.targetpath() )

def decider( machine, dirs ):
  if machine.isLinux():
    return ConfigureMakeBuilder
  if machine.isVS2008():
    return FreeTypeWindowsVS2008Builder
  else: #machine.isWindows():
    return FreeTypeWindowsBuilder

BUILDER = decider

